<?php
/*
批量修改订单功能


*/
/*php模拟POST*/
function ppp($url,$get='',$post=''){		
	
	if($post){
		if(is_array($post)){//数组
			$pcomm = '';
			foreach($post as $key => $val) {
					 if($pcomm == '') {
							 $pcomm .= $key.'='.urlencode($val);
					 } else {
							 $pcomm .= '&'.$key.'='.urlencode($val);
					 }
			}
		}else{
			$pcomm = $post;
		}
	}
		
	if(is_array($get)){//数组
		foreach($get as $key=>$value){
			$values[]="$key=".urlencode($value);	
		}
		$data_string=implode("&",$values);
	}else{
		$data_string=$get;//&号分隔
	}
	$comm = $data_string;

	 if($comm) {
			 if(strstr($url,'?')) {
					 $url = $url.'&'.$comm;
			 } else {
					 $url = $url.'?'.$comm;
			 }
	 }

	if($url) {
			 $cookies= '';
			 if(count($_COOKIE)) {
					 foreach($_COOKIE as $cookie_name => $cookie_var) {
							 $cookies .= $cookies != '' ? '; '.$cookie_name.'='.$cookie_var : $cookie_name.'='.$cookie_var;
					 }
			 }

			 $temp = @parse_url($url);
			 $temp['port'] = isset($temp['port']) ? $temp['port'] : 80;
			 $temp['path'] = isset($temp['path']) ? $temp['path'] : '/';
			 $temp['file'] = substr($temp['path'], strrpos($temp['path'], '/')+1);
			 $temp['dir'] = substr($temp['path'], 0, strrpos($temp['path'], '/'));
			 $temp['base'] = $temp['scheme'].'://'.$temp['host'].($temp['port'] != 80 ? ':'.$temp['port'] : '').$temp['dir'];
			 $temp['prev_dir'] = $temp['path'] != '/' ? substr($temp['base'], 0, strrpos($temp['base'], '/')+1) : $temp['base'].'/';
			 $fp = @fsockopen($temp['host'], $temp['port'], $errno, $errstr, 30); 
			 if($fp) {
					 if(!$post) {
							 $request.= "GET $temp[path]?$temp[query] HTTP/1.1\r\n";
					 } else {
							 $request.= "POST $temp[path]?$temp[query] HTTP/1.1\r\n";
							
					 }
					 $request.= "Host: $temp[host]\r\n"; 
					 $request.= "Accept: */*\r\n"; 
					 $request.= "Referer: http://$temp[host]/\r\n";
					 $request.= "Cookie: $cookies\r\n"; 
					 $request.= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\r\n"; 
					 $request.= "via: 1.1 JEJE1:80 (squid/2.5.STABLE4-NT-CVS)\r\n";
					// $request.= "X-Forwarded-For: $myip\r\n");
					 if($post) {
							 $request.= "Content-Type: application/x-www-form-urlencoded\r\n";
							 $request.= "Content-Length: ".strlen($pcomm)."\r\n\r\n";
							 $request.= $pcomm."\r\n";
					 }
					 $request.= "Connection: Keep-Alive\r\n\r\n";
					 
					 
					 @fputs($fp, $request);
	
					 while($str = @fread($fp, 4096)) {
	
							 if($str != "\r\n" && preg_match_all("#set-cookie:([^\r\n]*)#i", $str, $matches)) {
									 foreach($matches[1] as $cookie_info) {
											 preg_match('#^\s*([^=;,\s]*)=?([^;,\s]*)#', $cookie_info, $match) && list(, $name, $value) = $match;
											 preg_match('#;\s*expires\s*=([^;]*)#i', $cookie_info, $match) && list(, $expires) = $match;
											 $expires = isset($expires) ? strtotime($expires) : false;
											 $expires = (!is_numeric($expires) || time() > $expires) ? false : $expires;
											 setcookie($name, $value, $expires);
									 }
									 $str = str_replace($matches[0], '', $str);
							 }
							
							 $Content .= $str;
					 }
					 @fclose($fp);
					 
					 if(strpos($Content, 'Content-Type: text/html')) {
							 $Content = substr($Content, strpos($Content, 'Content-Type: text/html')+33);
					 } else {
							 $Content = substr($Content, strpos($Content, chr(0x0d).chr(0x0a).chr(0x0d).chr(0x0a))+4);
					 }

					 return  $Content;
			 }
	}

}
if (ENABLE_SSL == 'true') {
$link = HTTPS_SERVER ;
} else {
$link = HTTP_SERVER;
}

if($_POST['manager_submit']){ 
//print_r($_POST);
	
	$url = $link . '/admin/login.php';
	$ss =  ppp($url,$comm,'');
	
	
	$securityToken = explode('name="securityToken" value="',$ss);
	$securityToken = explode('"',$securityToken[1]);
	$securityToken = $securityToken[0];

	$comm = 'admin_name=admin&admin_pass=admin88&submit=Login&securityToken='.$securityToken;
	$ss =  ppp($url,'',$comm);

	$order_ids = explode(',',$_POST['order_ids']); 
	foreach($order_ids as $Oid){
		
		//echo $Oid;
		//echo '<br>';
		$pcomm = '';
		foreach($_POST as $key => $val) {
				 if($pcomm == '') {
						 $pcomm .= $key.'='.urlencode($val);
				 } else {
						 $pcomm .= '&'.$key.'='.urlencode($val);
				 }
		}
		$url = $link . "/admin/orders.php?page=1&oID={$Oid}&action=update_order&from=ajax";
		//$url ='http://www.baidu.com';
		//echo '<br>';echo '<br>';echo '<br>';
		//echo $url;
		//	echo '<br>';
		//echo dfopen($url,0,$pcomm,'',false,'127.0.0.1');
		$str =  ppp($url,'',$_POST);
		//echo $str;
		if(eregi('AJAX_OK',$str)){
			$msg .= "$Oid ". zen_get_order_no($Oid). " update_order OK<br>";
		}else{
			$msg .= "$Oid ". zen_get_order_no($Oid). " update_order Fail<br>";
		}
	}	 
	    

}		
?><!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<link rel="stylesheet" type="text/css" media="print" href="includes/stylesheet_print.css">
<link rel="stylesheet" type="text/css" href="includes/cssjsmenuhover.css" media="all" id="hoverJS">
<script language="javascript" src="includes/menu.js"></script>
<script language="javascript" src="includes/general.js"></script>
<script type="text/javascript">
  <!--
  function init()
  {
    cssjsmenu('navbar');
    if (document.getElementById)
    {
      var kill = document.getElementById('hoverJS');
      kill.disabled = true;
    }
  }
  // -->
</script>
<script language="javascript" type="text/javascript"><!--
function couponpopupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=450,height=280,screenX=150,screenY=150,top=150,left=150')
}
//--></script>
</head>
<body onLoad="init()">
<!-- header //-->
<div class="header-area">
<?php
  require(DIR_WS_INCLUDES . 'header.php');
?>
</div>
<!-- header_eof //-->
 
<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
  <tr>
  <td><strong>批量编辑</strong><br> <?php 
  if(!$order_ids)$order_ids = $_POST['order_ids'] ;
  foreach($order_ids as $Oid ){
	   echo $show_difference . zen_get_order_no($Oid); 
	   echo '<br>';
  }
$order_ids = implode(',',$order_ids);
if($msg){
	echo '<hr />';
  echo $msg;
  
}  
  ?></td>
  </tr>
  <tr>
    <td>
<form action="" method="post">
  <input type="hidden" value="<?php echo $order_ids ?>" name="order_ids">	
	<br>
	<?php echo zen_draw_textarea_field('comments', 'soft', '60', '5'); ?>
	<table border="0" cellspacing="0" cellpadding="2">
              <tr>
                <td class="main"><strong><?php echo ENTRY_STATUS; ?></strong> <?php echo zen_draw_pull_down_menu('status', $orders_statuses, $order->info['orders_status']); ?></td>
              </tr>
              <tr>
                <td class="main"><strong><?php echo ENTRY_NOTIFY_CUSTOMER; ?></strong> <?php echo zen_draw_checkbox_field('notify', '', true); ?></td>
                <td class="main"><strong><?php echo ENTRY_NOTIFY_COMMENTS; ?></strong> <?php echo zen_draw_checkbox_field('notify_comments', '', true); ?></td>
              </tr>
        </table>
    <p>

      <input type="submit" name="manager_submit" value="提交">
      <input name="Input" type="button" value="返回" onClick="location='?'">
    </p>
</form></td>
  </tr>
</table>
